/**
 * @category 新增常量
 * @author "songchenghong"
 * @version 2.0
 */

var addForm = "";//新增form对象
$(function(){
	
	addForm = $("#addForm");//获取新增form表单对象
	// 重置按钮渲染
	$("#btncancel").click(function(){
		addForm.form('reset');
		addForm.form("disableValidation");
	});
	sortCodeSelect();	//动态字典下拉框渲染
	addForm.form("disableValidation");	// 取消表单校验
	id = request.QueryString("id");//从跳转页面过来的
	
});


/**
 * 刷新grid
 */
function reloadGird() {
	gridReload("configList");
}


//增加操作
function addAccount(){
	
		if(addForm.form('enableValidation')){
//表单必填项通过
			addForm.form('submit',{
				url:'/addConfig',
				success:function(msg){
					msg = $.parseJSON(msg);
					
					if(msg.returnCode == '00'){
						top.showMessage("添加成功!");
						closeIframeWindow();
						reloadGird();
					}else{
						top.showMessage("<font color='red'>" + msg.returnMsg  + "</font>!");
					}	
				}
			});
		}
}
//动态下拉框
function sortCodeSelect() {
var  sortCodeSelectList =	$(".sortCodeSelect");
	for(var i=0;i<sortCodeSelectList.length;i++){  
		
	    var sortCodeBox=$(sortCodeSelectList[i]);  
	    var data = new Object();
	    
		data.sortCode = sortCodeBox.attr("sortCode");
		var result = postAsyncAjax('/findCodeListByCondition', data);
		sortCodeBox.combobox({
		    panelHeight : "auto",
			data : result,
			valueField : 'code',
			textField : 'name',
			editable : false,  
			loadFilter : function(data) {
				var obj = {};
				obj.code = '';
				obj.name = '-请选择-'
				data.splice(0, 0, obj)// 在数组0位置插入obj,不删除原来的元素
				return data;
			}
		});
		sortCodeBox.combobox('setValue', '');
	} 
}

//下拉框渲染
function comboboxSelect(url,selectItem,value,text,height,pwidth) {
		var result = postAsyncAjax(url);
		selectItem.combobox({
			width : pwidth,
		    panelHeight : height,
			data : result,
			valueField : value,
			textField : text,
			editable : false,
			loadFilter : function(data) {
				data = data.list;
				var obj = {};
				obj.passagewayNo = '';
				obj.name = '-请选择-'
				data.splice(0, 0, obj)// 在数组0位置插入obj,不删除原来的元素
				return data;
			}
		});
		selectItem.combobox('setValue', '');
}
